/**
 * Copyright (C), 2021, 因特驰
 * FileName: ZixunController
 * Author:   李晋武
 * Date:     2021/7/13 14:46
 * Description:
 * History:
 * 李晋武          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.esc.controller;

import com.esc.model.Zixun;
import com.esc.service.ZixunService;
import com.esc.util.PageResult;
import com.esc.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * 〈资讯〉<br>
 * 〈〉
 *
 * @author Yun
 * @create 2021/7/13
 * @since 1.0.0
 */
@Controller
@RequestMapping("zixun")
public class ZixunController {

    @Autowired
    private ZixunService zixunService;

    @RequestMapping("index")
    public String index(Model model, HttpServletRequest request){

        PageUtil<Zixun> pageUtil = new PageUtil<Zixun>();
        pageUtil.setPage(1);
        pageUtil.setRows(10);
        PageResult pageResult = zixunService.queryZixunList(pageUtil);
        model.addAttribute("zixunList",pageResult.getRows());

        //买家登录
        String buyerName = (String) request.getSession().getAttribute("buyerName");
        if (buyerName!=null){
            model.addAttribute("buyerName",buyerName);
            //request.getSession().setAttribute("sellerName","");
        }else {
            model.addAttribute("buyerName","");
        }
        //卖家登录
        String sellerName = (String) request.getSession().getAttribute("sellerName");
        if (sellerName!=null){
            model.addAttribute("sellerName",sellerName);
            //request.getSession().setAttribute("buyerName","");
        }else {
            model.addAttribute("sellerName","");
        }


        return "zixun/index";
    }

    @RequestMapping("queryZixunById")
    public String queryZixunById(Integer zixunid,Model model){
        Zixun zixun = zixunService.queryZixunById(zixunid);
        model.addAttribute("zixun",zixun);
        return "zixun/zixunxiangxi";
    }

//    @GetMapping("queryZixunList")
//    public PageResult queryZixunList(PageUtil<Zixun> pageUtil, Zixun zixun, Model model){
////        PageResult zixunList = zixunService.queryZixunList(pageUtil);
////        model.addAttribute("zixunList",zixunList);
//        return zixunService.queryZixunList(pageUtil);
//    }
}